package com.videomeetting.legend.videomeetting.activity.adapater;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.videomeetting.legend.videomeetting.R;
import com.videomeetting.legend.videomeetting.activity.bean.VideoBean;
import com.videomeetting.legend.videomeetting.activity.view.BorderTextView;

import java.util.List;

/**
 * Created by Administrator on 2018/4/11.
 */

public class FileChooseAdapater extends RecyclerView.Adapter<FileChooseAdapater.ViewHolder> {
    private Context mContext;
    List<VideoBean> videoBeans;
    private OnItemClickListener mOnItemClickListener;

    public List<VideoBean> getVideoBeans() {
        return videoBeans;
    }

    public void setVideoBeans(List<VideoBean> videoBeans) {
        this.videoBeans = videoBeans;
    }

    public OnItemClickListener getmOnItemClickListener() {
        return mOnItemClickListener;
    }

    public void setmOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public FileChooseAdapater(Context context, List<VideoBean> videoBeans) {
        this.mContext=context;
        this.videoBeans = videoBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.file_choose_item,null,false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
            if (videoBeans!=null&&videoBeans.size()>=1) {
                holder.fileName.setText(videoBeans.get(position).getName());
                holder.fileTime.setText(videoBeans.get(position).getTime());
                holder.fileLenght.setText(videoBeans.get(position).getLenght());
                holder.fileCreateData.setText(videoBeans.get(position).getFileCreateTime());
                if (mOnItemClickListener != null) {
                    //为ItemView设置监听器
                    holder.itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mOnItemClickListener.onItemClick(holder.itemView, position); // 2
                        }
                    });
                }
            }

    }

    @Override
    public int getItemCount() {
        if (videoBeans!=null&&videoBeans.size()>=0){
            return videoBeans.size();
        } else {
            return 4;
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        BorderTextView fileName;
        BorderTextView fileTime;
        BorderTextView fileLenght;
        BorderTextView fileCreateData;
        public ViewHolder(View itemView) {
            super(itemView);
            fileName = (BorderTextView) itemView.findViewById(R.id.file_choose_item_file_name);
            fileTime = (BorderTextView) itemView.findViewById(R.id.file_choose_item_file_time);
            fileLenght = (BorderTextView) itemView.findViewById(R.id.file_choose_item_file_lenght);
            fileCreateData = (BorderTextView) itemView.findViewById(R.id.file_choose_item_time);
        }
    }
    public interface OnItemClickListener{
        void onItemClick(View view,int position);
    }
}